import { ColliderCmp } from "./ecs/cmp/ColliderCmp";
import { Grid } from "./lib/kgame/d2/Grid";
import { QuadTree } from "./lib/kgame/d2/QuadTree";
import { IRect } from "./lib/kgame/util/Defined";

/**
 * 游戏事件
 */
export const enum GameEvent {
    snakeSpawn = "snakeSpawn",
    snakeDead = "snakeDead",
    snakeGhost = "snakeGhost",
    snakeRemove = "snakeRemove",
    foodEaten = "foodEaten",
}

/** 实体标签 */
export const enum EntityTag {
    food
}

/** 系统更新顺序 */
export const enum SysOrder {
    move,
    snake,
    food,
    collider,
    ai,
    chunk
}

/** 区块实体类型 */
export const enum ChunkEntityType {
    /** 蛇身 */
    snakeBody,
    food
}

/** 区块实体更新类型 */
export const enum ChunkEntityUpdateType {
    /** 变化类型 会实时更新在区块的位置 */
    update,
    /** 静态类型 只进行添加和删除 */
    static,
}


/** 碰撞器类型 */
export enum ColliderType {
    /** 不检测被碰撞 */
    none = 1 << 0,
    snake = 1 << 1,
    food = 1 << 2,
}

/** 碰撞组 */
export enum CollisionGroup {
    /** 不检测碰撞 */
    none = 0,
    eatFood = ColliderType.food,
    snake = ColliderType.snake,
}

/** 碰撞器更新类型 */
export enum ColliderUpdateType {
    /** 变化类型 会实时更新在容器的位置 */
    update,
    /** 静态类型 只进行添加和删除 */
    static
}

/** 碰撞器容器 */
export type ColliderContainer = QuadTree<ColliderCmp> | Grid<ColliderCmp>;
export type ColliderContainerDef = (rect: Readonly<IRect>) => ColliderContainer;
/** 碰撞器容器定义 */
export const colliderContainerFactory: { [key in ColliderType]: ColliderContainerDef } = {
    [ColliderType.none]: null,
    [ColliderType.snake]: rect => new QuadTree(rect, 20, 5),
    [ColliderType.food]: rect => new Grid(rect, 10, 10),
}